/*
 * @Author: wangchao
 * @Date: 2024-10-04 13:44:23
 * @LastEditors: wangchao
 * @LastEditTime: 2024-10-08 09:17:10
 * @FilePath: \JD-RTT-Driver\applications\u_port.h
 * @Description:
 * Copyright (c) 2024 by Bingshan Guardian, All Rights Reserved.
 */

#ifndef _U_PORT_H_
#define _U_PORT_H_

#include <rtdevice.h>
#include <rtthread.h>
#include "board.h"

#define PCA555_I2C_BUS_NAME                  "i2c2"
#define PCA555_1_ADDR                        0x20 /* U17 从机地址 */
#define PCA555_2_ADDR                        0x22 /* U18 从机地址 */
#define PCA555_3_ADDR                        0x24 /* U19 从机地址 */
#define PCA555_4_ADDR                        0x26 /* U20 从机地址 */
#define get_low_byte(value)                  ((uint8_t)((value)&0xff))
#define get_high_byte(value)                 ((uint8_t)((value) >> 8))
#define port_bit_read(value, bit)            (((value) >> (bit)) & 0x01)
#define port_bit_set(value, bit)             ((value) |= (1 << (bit)))
#define port_bit_clear(value, bit)           ((value) &= ~(1 << (bit)))
#define port_bit_write(value, bit, bitvalue) (bitvalue ? port_bit_set(value, bit) : port_bit_clear(value, bit))

typedef void (*SetDOHandler)(rt_uint8_t, rt_uint8_t);
typedef void (*SetDOWordHandler)(rt_uint16_t);
typedef rt_uint8_t (*GetDOHandler)(rt_uint8_t);
typedef rt_uint16_t (*GetDOWordHandler)(void);
typedef struct
{
    GetDOHandler GET;
    SetDOHandler SET;
} SYSTEM_DO_HANDLE;
extern SYSTEM_DO_HANDLE APP_DO;

typedef rt_uint8_t (*GetDIHandler)(rt_uint8_t);
typedef rt_uint32_t (*GetDIWordHandler)(void);
typedef struct
{
    GetDIWordHandler GET_WORD;
    GetDIHandler GET;
} SYSTEM_DI_HANDLE;
extern SYSTEM_DI_HANDLE APP_DI;

rt_bool_t is_push_emergency_button(void);

#endif